/**
 * \file TimeMeasure_Linux.h
 * \brief TimeMeasure definition class for Linux platforms.  Object used to measure time (even short)
 * \author Edouard ROGE
 * \date 07 august 2012
 */

#ifndef _TIMEMEASURE_LINUX_
#define _TIMEMEASURE_LINUX_

#include <vector>
#include <sys/time.h>
#include "Core/Memory/HeapObject.h"
#include "Core/Thread/Mutex.h"

/**
 * \class TimeMeasure
 * \brief Measure elapsed time between one moment and another
 */
class TimeMeasure : public HeapObject
{
public:
	/**
	 * \fn TimeMeasure();
	 * \brief Default constructor
	 */
	TimeMeasure();

	/**
	 * \fn ~TimeMeasure();
	 * \brief Destructor
	 */
	~TimeMeasure();

	/**
	 * \fn uint32 AddMeasure();
	 * \return created index of the new time measure
	 * \brief Create and add a new time measure
	 */
	uint32 AddMeasure();

	/**
	 * \fn void Start(uint32 _iIndex);
	 * \param _iIndex index of the time measure to start
	 * \brief Start the measure of time for the index in parameter
	 */
	void Start(uint32 _iIndex);

	/**
	 * \fn void Stop(uint32 _iIndex);
	 * \param _iIndex index of the time measure to stop
	 * \brief Stop the measure of the time for the index in parameter
	 */
	void Stop(uint32 _iIndex);

	/**
	 * \fn float GetMeasure(int32 _iIndex) const;
	 * \param _iIndex index of the time measure to get the elapsed time between its start and its stop
	 * \return time elapsed
	 * \brief Compute elapsed time in milliseconds between start and stop
	 */
	float GetMeasure(int32 _iIndex) const;

private:

	/** Stored measured times, 2n=start time index 'n', 2n+1=end time index 'n'*/
	std::vector<timeval> m_Measures;

	/** Mutex */
	Mutex m_Mutex;
};

#endif // _TIMEMEASURE_LINUX_
